package com.ymatou.iapi.anlimember.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.anlimember.parameter.BindInviteRelationReq;
import com.ymatou.iapi.anlimember.service.BindInviteRelationCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P3;
import com.ymttest.database.model.anlihui.InviteRelation;
import com.ymttest.database.sqlwapper.anlihui.InviteRelationWrapper;
import com.ymttest.utils.TestDataManager;

public class Ts_BindInviteRelation {
	
	private static BindInviteRelationReq bindInviteRelationReq;
	private static BindInviteRelationCall bindInviteRelationCall;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("绑定邀请关系");
	}

	@Before
	public void caseUp() {
		bindInviteRelationReq = new BindInviteRelationReq();
		bindInviteRelationCall = new BindInviteRelationCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(bindInviteRelationCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	public static void verify() {
		
		InviteRelationWrapper wrapper = new InviteRelationWrapper();
		
		InviteRelation actual = wrapper.selectByInviteeIdAndInviterId(
				bindInviteRelationReq.getUserId(),
				bindInviteRelationReq.getInviterId());
		
		Logger.verifyEquals((byte)1, actual.getInvite_type(), "验证Invite_type");
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_BindInviteRelation_001() {
		Logger.start(true, "邀新绑定邀请关系成功");
		try {
			
			bindInviteRelationReq.setInviterId(Long.parseLong(TestDataManager
					.getRandomNum(10)));
			bindInviteRelationReq.setUserId(Long.parseLong(TestDataManager
					.getRandomNum(10)));

			bindInviteRelationCall.setData(bindInviteRelationReq);
			bindInviteRelationCall.callService();
			
			verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_BindInviteRelation_002() {
		Logger.start(true, "邀请人为null，邀请失败");
		try {
			
			bindInviteRelationReq.setInviterId(null);
			bindInviteRelationReq.setUserId(Long.parseLong(TestDataManager
					.getRandomNum(10)));

			bindInviteRelationCall.setData(bindInviteRelationReq);
			bindInviteRelationCall.callService();
			
			Logger.verifyEquals(400, bindInviteRelationCall.getCode(), "验证code");
			Logger.verifyEquals("inviterId:邀请人id", bindInviteRelationCall.getMsg(), "验证msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_BindInviteRelation_003() {
		Logger.start(true, "被邀请人为null，邀请失败");
		try {
			
			bindInviteRelationReq.setInviterId(Long.parseLong(TestDataManager
					.getRandomNum(10)));
			bindInviteRelationReq.setUserId(null);

			bindInviteRelationCall.setData(bindInviteRelationReq);
			bindInviteRelationCall.callService();
			
			Logger.verifyEquals(400, bindInviteRelationCall.getCode(), "验证code");
			Logger.verifyEquals("userId:新用户id", bindInviteRelationCall.getMsg(), "验证msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
